package cn.signalpha.modules.base.service;

import cn.signalpha.core.tool.utils.ObjectUtil;
import cn.signalpha.modules.base.entity.Notice;
import cn.signalpha.modules.base.mapper.NoticeMapper;
import cn.signalpha.modules.base.vo.NoticeVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 服务类
 *
 * @author signalpha
 */
@Service
public class NoticeService extends ServiceImpl<NoticeMapper, Notice> {

	/**
	 * 自定义分页
	 */
    public IPage<NoticeVO> selectNoticePage(IPage<NoticeVO> page, Map<String, Object> params) {
        return page.setRecords(baseMapper.selectNoticePage(page, params));
    }

    /**
	 * 自定义Wrappers
	 */
    public QueryWrapper<Notice> selectNoticeWrapper(Map<String, Object> params) {
        QueryWrapper<Notice> wrapper = Wrappers.query();
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("id")), Notice::getId, params.get("id"));
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("userId")), Notice::getUserId, params.get("userId"));
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("category")), Notice::getCategory, params.get("category"));
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("targetId")), Notice::getTargetId, params.get("targetId"));
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("targetType")), Notice::getTargetType, params.get("targetType"));
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("content")), Notice::getContent, params.get("content"));
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("status")), Notice::getStatus, params.get("status"));
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("createTime")), Notice::getCreateTime, params.get("createTime"));
        wrapper.lambda().orderByDesc(Notice::getId);
        return wrapper;
    }

}

